package com.biyabi.service.impl;

import com.biyabi.dao.CommentMapper;
import com.biyabi.entity.Comment;
import com.biyabi.entity.CommentExample;
import com.biyabi.service.CommentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class CommentServiceImpl implements CommentService {
    @Resource
    private CommentMapper commentMapper;
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<Comment> findByUserAndreceive(String userId){
        CommentExample example = new CommentExample();
        example.createCriteria().andTouseridEqualTo(userId);
        return commentMapper.selectByExample(example);
    }
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public List<Comment> findByUserAndsend(String userId){
        CommentExample example = new CommentExample();
        example.createCriteria().andUseridEqualTo(userId);
        return commentMapper.selectByExample(example);
    }

    @Override
    public void add(Comment comment) {
        comment.setId(UUID.randomUUID().toString());
        commentMapper.insert(comment);
    }
}
